package cn.jr.dao.impl;

import cn.jr.dao.IUserDao;
import cn.jr.pojo.ShopRun;
import cn.jr.util.DBHelper;

import java.util.ArrayList;

@SuppressWarnings("all")
public class UserDaoImpl implements IUserDao {

    DBHelper db = new DBHelper();

    @Override
    public int insertUser(ShopRun shop) {
        String sql = "insert into tshoprun values(null,?,?)";
        Object[] objs = {shop.getUserName(), shop.getPassword()};
        return db.dtUpdate(sql, objs);
    }

    @Override //通过主键(userId) 查询 用户名
    public ShopRun selectUserByUserId(Integer userId) {
        String sql = "select * from tshoprun where userId=?";
        ArrayList<ShopRun> list = db.dtQuery(sql, ShopRun.class, userId);
        return list.size() > 0 ? list.get(0) : new ShopRun();
    }

    @Override //通过 用户名 查询
    public ShopRun selectUserByUserName(String userName) {
        String sql = "select * from tshoprun where userName=?";
        ArrayList<ShopRun> list = db.dtQuery(sql, ShopRun.class, userName);
        return list.size() > 0 ? list.get(0) : new ShopRun(0,null,null);
    }

    /*@Override//查询总条数
    public int selectCountByShopRunAndPageHelper(ShopRun shop) {
        StringBuilder sql = new StringBuilder("select count(*) from tshoprun");
        Connection con = db.getCon();
        PreparedStatement ps = null;
        ResultSet rs = null;

        ps= con.prepareStatement(sql.toString());

        return 0;
    }

    @Override //查询当前页面的集合数据
    public ArrayList<ShopRun> selectByUser(ShopRun shop, PageHelper ph) {
        return null;
    }*/
}
